package com.yiyang.pojo;

import lombok.Data;

@Data
public class Result<T> {
    // 响应的自定义的状态码
    private Integer code;
    // 响应的提示信息
    private String message;
    // 响应的数据
    private T data;

    private Long total;

    public static <T> Result<T> success() {
        Result<T> result = new Result();
        result.setCode(Code.SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result();
        result.setCode(Code.SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> success(T data,Long total){
        Result<T> result = new Result();
        result.setCode(Code.SUCCESS);
        result.setMessage("成功");
        result.setData(data);
        result.setTotal(total);
        return result;
    }

    public static <T> Result<T> fail() {
        Result<T> result = new Result();
        result.setCode(Code.FAIL);
        result.setMessage("失败");
        return result;
    }
}
